package com.itc.bpm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itc.bpm.bean.BpmModelTaskCustomVariables;
import com.itc.bpm.mapper.BpmModelTaskCustomVariablesMapper;
import com.itc.bpm.service.BpmModelTaskCustomVariablesService;
import com.itc.bpm.util.JsonUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 流程定义任务参数
 */
@Service
public class BpmModelTaskCustomVariablesServiceImpl extends ServiceImpl<BpmModelTaskCustomVariablesMapper, BpmModelTaskCustomVariables> implements BpmModelTaskCustomVariablesService {
    @Resource
    BpmModelTaskCustomVariablesMapper bpmModelTaskCustomVariablesMapper;
    @Override
    public void clearVaribles(String definitionId) {
        bpmModelTaskCustomVariablesMapper.clearVaribles(definitionId);
    }

    @Override
    public Map<String,String> getTaskVariables(String processDefinitionId, String id) {
        BpmModelTaskCustomVariables taskCustomVariables = this.getOne(new LambdaQueryWrapper<BpmModelTaskCustomVariables>().eq(BpmModelTaskCustomVariables::getTaskKey,id).eq(BpmModelTaskCustomVariables::getProcessDefinitionId,processDefinitionId));
        Map<String,String> map = new HashMap<>();
        if(taskCustomVariables!=null){
            map = JsonUtils.jsonToMap(taskCustomVariables.getVaribalesJson(),String.class);
        }
        return map;
    }
}
